/*
ID: aube1412
PROG: beads
LANG: C++11
*/

#include <iostream>
#include <algorithm>
#include <fstream>
#include <unordered_map>
#include <deque>

std::ifstream fin ("beads.in");
std::ofstream fout ("beads.out");

std::unordered_map<char, int> bead{{'r', 1}, {'b', 2}, {'w', 3}};
std::deque<int> necklace; // 1: red, 2: blue, 3: white
int n;

bool inrange(int x) { return 0 <= x && x < n; }

int get_color(int start, int dir)
{
	for (auto i = start; inrange(i); i += dir)
		if (necklace[i] != 3) return necklace[i];
	return 3;
}

int count(int start, int dir)
{
	auto tot = 0;
	auto co = get_color(start, dir);
	for (auto i = start; inrange(i); i += dir, tot++)
		if (!(necklace[i] & co)) break;
	return tot;
}

int main()
{
	fin >> n;
	for (auto i = 0; i < n; i++) {
		char ch;
		fin >> ch;
		necklace.push_back(bead[ch]);
	}
	auto max = 0;
	for (auto i = 0; i < n; i++) {
		max = std::max(max, std::min(n, count(0, 1) + count(n-1, -1)));
		necklace.push_back(necklace.front());
		necklace.pop_front();
	}
	fout << max << '\n';
}

